package com.bluetool.debby.bluetoothjob.Utils;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.provider.Settings;
import android.widget.Toast;


/**
 * Created by debby on 2018/5/3.
 * 描述:
 */

public class BlueToothUtil {
    public static final int REQUEST_ENABLE = 4396;
    public static final int REQUEST_LOCATION_ENABLE = 957;

    //开启蓝牙
    public static void openBle(Activity activity) {
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        activity.startActivityForResult(intent, REQUEST_ENABLE);
    }


    //开启定位权限
    public static void openLocation(Activity activity) {
        LocationManager lm = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
        if (lm != null) {
            boolean ok = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
            if (!ok) {
                Toast.makeText(activity, "系统检测到未开启GPS定位服务", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent();
                intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                activity.startActivityForResult(intent, REQUEST_LOCATION_ENABLE);
            }
        } else {
            Toast.makeText(activity, "开启定位失败", Toast.LENGTH_SHORT).show();
        }
    }

}
